<template>
    <div >
      <zh-card title="">
      <zh-form :model="state.queryParams" ref="queryFormRef" label-width="150px">
        <zh-form-input prop="fileClassCode" label="文件分类编码"  v-model="state.queryParams.fileClassCode" :span="8"
                       :disabled="false"></zh-form-input>
                       
        <zh-form-input prop="classTitle" label="分类标题"  v-model="state.queryParams.classTitle" :span="8"
                       :disabled="false"></zh-form-input>
        <zh-form-select
            prop="appId"
            :lazy="true"
            label="所属应用"
            :span="8"
            v-model="state.queryParams.appId"
            :fieldNames="{ label: 'appName', value: 'appId' }"
            funcCode="application0012"
            :disabled="false"
            searchField="appName"
        ></zh-form-select>

        <!-- <zh-form-select
            prop="permitAppId"
            :lazy="true"
            label="许可应用"
            :span="8"
            v-model="state.queryParams.permitAppId"
            :fieldNames="{ label: 'appName', value: 'appId' }"
            funcCode="application0012"
            :disabled="false"
            searchField="appName"
        ></zh-form-select>   -->
                       
        <zh-form-date
				prop="expireTimeStart"
                :span="8"
				label="开始到期时间"
				placeholder="请输入开始到期时间"
				type="datetime"
				v-model="state.queryParams.expireTimeStart"
			></zh-form-date>
        <zh-form-date
				prop="expireTimeEnd"
                :span="8"
				label="开始到期时间"
				placeholder="请输入开始到期时间"
				type="datetime"
				v-model="state.queryParams.expireTimeEnd"
			></zh-form-date>
        <zh-form-query v-model="state.advanced" @queryClick="queryfileAppRead" :formRef="queryFormRef" :span="8"> 
            <zh-button buttonType="add" @click="saveAdd">授权应用新增</zh-button>
            <zh-button buttonType="add" @click="readAdd">应用读取授权</zh-button>
        </zh-form-query>
      </zh-form>
    
      </zh-card>
      <div >
        <zh-row>
            <zh-col :span="12">
                <zh-table title="文件应用读取授权" ref="fileAppReadTable" size="mini"  :url="VITE_FILE_API_URL+'fileAppRead0001'"
                    :columns="state.tableColumns" highlight-current-row>            
                </zh-table>
            </zh-col>

            <zh-col :span="12">                
                <zh-table title="文件应用分类存储授权" ref="fileAppClassTable" size="mini" :url="VITE_FILE_API_URL+'fileAppRead0007'"
                    :columns="state.tableColumns2" highlight-current-row>            
                </zh-table>                  
            </zh-col>
        </zh-row>
    </div>
      

    <zh-dialog
          ref="appClassDialog"
          v-model="state.fileAppReadVisible"
          title="授权读取文件信息" 
          :bodyStyle="state.bodyStyle"
          width="40%">
            <FileAppReadInfo :displayFlag="false" ref="fileAppReadInfo">
            </FileAppReadInfo>
            <template #footer>
                <span class="dialog-footer">
                    <zh-button @click="state.fileAppReadVisible = false" >取消</zh-button>
                    <zh-button v-if="!state.showFlag" type="primary" @click="saveFileAppRead">
                        保存
                    </zh-button>
                </span>
            </template>
        </zh-dialog> 
        <zh-dialog
          ref="appClassDialog"
          v-model="state.fileAppClassInfoVisible"
          title="授权应用新增" 
          :bodyStyle="state.bodyStyle"
          width="40%">
            <FileAppClassInfo :displayFlag="false" ref="fileAppClassInfo">
            </FileAppClassInfo>
            <template #footer>
                <span class="dialog-footer">
                    <zh-button @click="state.fileAppClassInfoVisible = false" >取消</zh-button>
                    <zh-button v-if="!state.showFlag" type="primary" @click="saveFileAppClassInfo">
                        保存
                    </zh-button>
                </span>
            </template>
        </zh-dialog>  
       
    </div>
</template>

<script lang="ts" setup name="fileApplyIndex">
// import {  Edit } from '@element-plus/icons-vue'
import FileAppReadInfo from '@/views/fileCenter/fileApply/component/FileAppReadInfo.vue';
import FileAppClassInfo from '@/views/fileCenter/fileApply/component/FileAppClassInfo.vue';
const VITE_FILE_API_URL = import.meta.env.VITE_FILE_API_URL as string+'/doc/api/';

const queryFormRef = ref();
const fileAppReadTable = ref();
const fileAppClassTable = ref();
const fileAppReadInfo=ref();
const fileAppClassInfo=ref();

const state = reactive({
    visible:true,
    showFlag:false,
    fileAppReadVisible:false,
    fileAppClassInfoVisible:false,
    advanced: false,
    bodyStyle: {
      height: 'calc(100vh - 200px)',
      
    },
    queryParams: {
        fileClassCode:'',
        classTitle:'',
        appId:'',
        permitAppId:'',
        expireTime:'',
        expireTimeStart:'',
        expireTimeEnd:'',
    },

    tableColumns: [
        { type: 'seq', width: 60, fixed: 'left', align: 'center', title: '序号' },
       { field: 'classTitle', title: '文件分类标题', visible: true, fixed: 'left',align: 'center', width: 120 },
      { field: 'appName', title: '应用名称', visible: true, fixed: 'left',align: 'center', width: 120 },
      { field: 'fileClassCode', title: '文件分类编号', visible: true, align: 'center', width: 120 },
        { field: 'appId', title: '应用ID', visible: false, align: 'center', width: 120 },
        { field: 'secrecyLevel', title: '保密级别', visible: false, align: 'center', width: 120 },
        { field: 'secrecyLevelName', title: '保密级别', visible: true,align: 'center', width: 120 },
        { field: 'expireTime', title: '过期时间',type:'Date', visible: true, align: 'center', width: 120 },
      { field: 'authStatusName', title: '审核状态', visible: true, align: 'center', width: 120 },
      { field: 'auditOpinion', title: '审核意见', visible: true, align: 'center', width: 120 },
      { field: 'createTime', title: '申请时间',type:'Date', visible: true, align: 'center', width: 120 },
    ],
    tableColumns2: [
        { type: 'seq', width: 60, fixed: 'left', align: 'center', title: '序号' },
        { field: 'fileClassTitle', title: '文件分类标题', visible: true, fixed: 'left',align: 'center', width: 120 },
        { field: 'appId', title: '应用ID', visible: false, align: 'center', width: 120 },
        { field: 'appName', title: '应用名称', visible: true, fixed: 'left',align: 'center', width: 120 },
      { field: 'fileClassCode', title: '文件分类编号', visible: true, align: 'center', width: 120 },
      { field: 'fileClassPath', title: '文件存放路径', visible: true,align: 'center', width: 120 },
        { field: 'expireTime', title: '过期时间',type:'Date', visible: true, align: 'center', width: 120 },
      { field: 'authStatusName', title: '审核状态', visible: true, align: 'center', width: 120 },
      { field: 'auditOpinion', title: '审核意见', visible: true, align: 'center', width: 120 },
      { field: 'createTime', title: '申请时间',type:'Date', visible: true, align: 'center', width: 120 },

    ],


});


//--------------------------定义调用方法--------------------------------------------------
 const queryfileAppRead = () => {
    //查询读取权限
    fileAppReadTable.value.query(state.queryParams);
    // 查询保存权限
    fileAppClassTable.value.query(state.queryParams);
 }

 const readAdd = () => {     
    state.fileAppReadVisible=true;   
 }

 //保存新增的文件读取授权
 const saveFileAppRead= () => { 
    console.log('indd:'+fileAppReadInfo.value.getCheckedKeys());    
    let fileAppReadparams = fileAppReadInfo.value.fileAppReadInfo;
    fileAppReadparams.authStatus = '0';
    fileAppReadparams.fileClassCodeList=fileAppReadInfo.value.getCheckedKeys();
    $api.common.fileSend.post('fileAppRead0008', fileAppReadparams).then(() => {
        $messageBox.success('保存成功', '提示');  
        state.fileAppReadVisible=false;
        queryfileAppRead();  
      }).catch(() => {}); 
 
  
}

const saveFileAppClassInfo=()=>{
    console.log('inddss:'+fileAppClassInfo.value.getCheckedKeys());
    let fileAppClassparams = fileAppClassInfo.value.appClassInfo;
    fileAppClassparams.authStatus = '0';
    fileAppClassparams.fileClassCodeList=fileAppClassInfo.value.getCheckedKeys();
    $api.common.fileSend.post('fileAppClass0009', fileAppClassparams).then(() => {
        $messageBox.success('保存成功', '提示');  
        state.fileAppClassInfoVisible=false; 
        queryfileAppRead(); 
    })


}

 const saveAdd = () => {
    state.fileAppClassInfoVisible=true;  
 }

</script>
